home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / www / cern / proxy-support / Mosaic-2.4 / HTAccess.c.patch.Z / HTAccess.c.patch
Encoding:
Text File  |  1994-05-11  |  2.9 KB  |  124 lines

  1. *** HTAccess.c.ORIG    Thu May 12 14:18:55 1994
  2. --- HTAccess.c    Thu May 12 14:25:36 1994
  3. ***************
  4. *** 108,113 ****
  5. --- 108,192 ----
  6.   }
  7.   
  8.   
  9. + /*                            override_proxy()
  10. + **
  11. + **    Check the no_proxy environment variable to get the list
  12. + **    of hosts for which proxy server is not consulted.
  13. + **
  14. + **    no_proxy is a comma- or space-separated list of machine
  15. + **    or domain names, with optional :port part.  If no :port
  16. + **    part is present, it applies to all ports on that domain.
  17. + **
  18. + **    Example:
  19. + **        no_proxy="cern.ch,some.domain:8001"
  20. + **
  21. + */
  22. + PRIVATE BOOL override_proxy ARGS1(CONST char *, addr)
  23. + {
  24. +     CONST char * no_proxy = getenv("no_proxy");
  25. +     char * p = NULL;
  26. +     char * host = NULL;
  27. +     int port = 0;
  28. +     int h_len = 0;
  29. +     if (!no_proxy || !addr || !(host = HTParse(addr, "", PARSE_HOST)))
  30. +     return NO;
  31. +     if (!*host) { free(host); return NO; }
  32. +     if (p = strchr(host, ':')) {    /* Port specified */
  33. +     *p++ = 0;            /* Chop off port */
  34. +     port = atoi(p);
  35. +     }
  36. +     else {                /* Use default port */
  37. +     char * access = HTParse(addr, "", PARSE_ACCESS);
  38. +     if (access) {
  39. +         if        (!strcmp(access,"http"))    port = 80;
  40. +         else if (!strcmp(access,"gopher"))    port = 70;
  41. +         else if (!strcmp(access,"ftp"))    port = 21;
  42. +         free(access);
  43. +     }
  44. +     }
  45. +     if (!port) port = 80;        /* Default */
  46. +     h_len = strlen(host);
  47. +     while (*no_proxy) {
  48. +     CONST char * end;
  49. +     CONST char * colon = NULL;
  50. +     int templ_port = 0;
  51. +     int t_len;
  52. +     while (*no_proxy && (WHITE(*no_proxy) || *no_proxy==','))
  53. +         no_proxy++;            /* Skip whitespace and separators */
  54. +     end = no_proxy;
  55. +     while (*end && !WHITE(*end) && *end != ',') {    /* Find separator */
  56. +         if (*end==':') colon = end;            /* Port number given */
  57. +         end++;
  58. +     }
  59. +     if (colon) {
  60. +         templ_port = atoi(colon+1);
  61. +         t_len = colon - no_proxy;
  62. +     }
  63. +     else {
  64. +         t_len = end - no_proxy;
  65. +     }
  66. +     if ((!templ_port || templ_port == port)  &&
  67. +         (t_len > 0  &&  t_len <= h_len  &&
  68. +          !strncmp(host + h_len - t_len, no_proxy, t_len))) {
  69. +         free(host);
  70. +         return YES;
  71. +     }
  72. +     if (*end) no_proxy = end+1;
  73. +     else break;
  74. +     }
  75. +     free(host);
  76. +     return NO;
  77. + }
  78.   /*        Find physical name and access protocol
  79.   **        --------------------------------------
  80.   **
  81. ***************
  82. *** 137,143 ****
  83.   */
  84.   #define USE_GATEWAYS
  85.   #ifdef USE_GATEWAYS
  86. !     {
  87.       char *gateway_parameter, *gateway, *proxy;
  88.   
  89.       /* search for gateways */
  90. --- 216,226 ----
  91.   */
  92.   #define USE_GATEWAYS
  93.   #ifdef USE_GATEWAYS
  94. !     /* make sure the using_proxy variable is false */
  95. !     using_proxy = NO;
  96. !     if (!override_proxy(addr)) {
  97.       char *gateway_parameter, *gateway, *proxy;
  98.   
  99.       /* search for gateways */
  100. ***************
  101. *** 168,176 ****
  102.           gateway = DEFAULT_WAIS_GATEWAY;
  103.       }
  104.   #endif
  105. -     /* make sure the using_proxy variable is false */
  106. -     using_proxy = NO;
  107.   
  108.       /* proxy servers have precedence over gateway servers */
  109.       if (proxy) {
  110. --- 251,256 ----
  111.